import { Controller, Post, Body } from '@nestjs/common';
import { RoleService } from './role.service';
import { CreateRoleDto, FindRoleDto, UpdateRoleDto, RemoveRoleDto, CreateBatchRoleDto, RemoveBatchRoleDto, FindPermissionByRoleDto } from './dto/role.dto';
import { Authority } from '@/common/decorators/authority.decorator';
import { useResult } from '@/common/hooks/useResult';

@Controller('role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @Post('create')
  @Authority('role:create')
  async create(@Body() body: CreateRoleDto) {
    const res = await this.roleService.create(body);
    return useResult(res);
  }

  @Post('findAll')
  @Authority('role:find')
  async findAll(@Body() body: FindRoleDto) {
    const res = await this.roleService.findAll(body);
    return useResult(res);
  }

  @Post('findOne')
  @Authority('role:find')
  async findOne(@Body() body: FindRoleDto) {
    const res = await this.roleService.findOne(body);
    return useResult(res);
  }

  @Post('findPermissionByRole')
  @Authority('admin*')
  async findPermissionByRole(@Body() body: FindPermissionByRoleDto) {
    const res = await this.roleService.findPermissionByRole(body);
    return useResult(res);
  }

  @Post('update')
  @Authority('role:update')
  async update(@Body() body: UpdateRoleDto) {
    const res = await this.roleService.update(body);
    return useResult(res);
  }

  @Post('remove')
  @Authority('role:remove')
  async remove(@Body() body: RemoveRoleDto) {
    const res = await this.roleService.remove(body);
    return useResult(res);
  }

  @Post('removeBatch')
  @Authority('role:remove')
  async removeBatch(@Body() body: RemoveBatchRoleDto) {
    const res = await this.roleService.removeBatch(body);
    return useResult(res);
  }

  @Post('createBatch')
  @Authority('role:create')
  async createBatch(@Body() body: CreateBatchRoleDto) {
    const res = await this.roleService.createBatch(body);
    return useResult(res);
  }
}
